import {
  PageResult,
  DisableRes,
  ContactGroup,
  putContactGroupDto,
  ContactGroupGateway,
  disableContactGroupDto,
  ContactGroupInterfaceWithPrimary,
  PutMutiRes,
} from "qqlx-core";

import { ViewBase, ViewBaseAction } from "../view-base";
import { ContactGroupSchema } from "@/pond/schema-contact";

export class ViewContactGroup extends ViewBase<ContactGroup> implements ViewBaseAction<ContactGroup>, ContactGroupInterfaceWithPrimary<{}> {
  private static instance: ViewContactGroup;
  static getInstance(options?: { isSingleton?: boolean }) {
    if (options?.isSingleton === false) {
      return new ViewContactGroup();
    }

    if (!this.instance) this.instance = new ViewContactGroup();
    return this.instance;
  }

  private constructor() {
    super();
    this.initial();
    this.insertDefaultCondition();
  }

  getSchema(): ContactGroup {
    return new ContactGroupSchema();
  }

  async get() {
    this.pending();
    return this.$request.get<{}, PageResult<ContactGroup>>(ContactGroupGateway.path);
  }

  put() {
    this.pending();
    const dto = { schemaList: this.data.schemaList };
    return this.$request.put<putContactGroupDto, PutMutiRes<ContactGroup>>(ContactGroupGateway.path, dto);
  }

  async disable(dto: disableContactGroupDto) {
    this.pending();
    return this.$request.delete<disableContactGroupDto, DisableRes>(ContactGroupGateway.path, dto);
  }
}
